<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>下级设备</title>
	<link href="../css/public.css" rel="stylesheet"/>
	<link href="../css/main.css" rel="stylesheet"/>
	<link href="../css/style.css" rel="stylesheet"/>
	<link href="../css/agent.css?v=1" rel="stylesheet"/>

	<script src="./js/jquery-1.9.1.js"></script>

	<script src="../js/swiper.min.js"></script>
	<script src="../js/mobile-util.js"></script>
	<script src="../js/public.js"></script>
	<script src="../js/layer/layui.js"></script>
	<script src="../js/jquery.cookie.js"></script>
    <script src="../../mifiadmin/js/common.js"></script>

	<script>
		/*获取url参数*/
		function getUrlParam(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
			var r = window.location.search.substr(1).match(reg);  //匹配目标参数
			if (r != null) return unescape(r[2]); return null; //返回参数值
		}

		/*获取url参数end*/
	</script>

</head>
<body >

<header class="mui-bar mui-bar-nav indexheader bluebg flex">
	<div class="headerlogo" onclick="back()">
		<i class="iconfont backbtn">&#xe602;</i>
	</div>

	<div class="headertitle">
		<p>下级设备</p>
	</div>

	<div class="headerright timeright hide">
		<p class="timepbox iconfont">&#xe6d9;</p>
	</div>

</header>

<main class="agentbox">

	<div class="tit-flash-sale p mytit_flash">

			<ul class="mydevice">
				<li class="co-deepblue" onclick="device(this,0)" data-type="0">
					<a href="javascript:void(0)" class="tab_head">设备总数(<em id="alldevice"></em>台)</a>
				</li>

				<li id="WAITPAY" onclick="device(this,1)" data-type="1">
				<a href="javascript:void(0)" class="tab_head">已激活(<em id="devicejihuo"></em>台)</a>
				</li>

				<li id="WAITSEND" onclick="device(this,2)" data-type="2">
					<a href="javascript:void(0)" class="tab_head">未激活(<em id="divecenull"></em>台)</a>
				</li>

			</ul>

	</div>


	<div class="devicebox">

		<!--设备总数-->
		<div class="devicelistbox" id="total">
			<div class="flex devicehead">
				<div class="flex-1">设备号</div>
				<div class="flex-1">套餐</div>
				<div class="flex-1">激活时间</div>
			</div>

			<div class="nulldecice">
				<p class="iconfont ">&#xe6ed;</p>
				<p class="nulldevicetitle">您还没有wifi设备</p>
			</div>

			<div class="deviceinfo" id="totallist">


				<!--<div class="flex devicelist">-->
					<!--<div class="flex-1">-->
						<!--1111111-->
					<!--</div>-->
					<!--<div class="flex-1">-->
						<!--三个月包月套餐-->
					<!--</div>-->
					<!--<div class="flex-1">-->
						<!--2018-1-1-->
					<!--</div>-->
				<!--</div>-->


			</div>

			<div class="businessmore hide" onclick="ajax_device_submit()">
				<p>查看等多</p>
				<p class="companyicon businessmoreicon">
					<i class="iconfont comicon">&#xe624;</i>
				</p>
			</div>

		</div>

		<!--设备总数end-->

		<!--已激活设备设备-->
		<div class="devicelistbox" id="activation">
			<div class="flex devicehead">
				<div class="flex-1">设备号</div>
				<div class="flex-1">套餐</div>
				<div class="flex-1">激活时间</div>
			</div>

			<div class="nulldecice">
				<p class="iconfont ">&#xe6ed;</p>
				<p class="nulldevicetitle">您还没有wifi设备</p>
			</div>

			<div class="deviceinfo" id="activationlist">

				<!--<div class="flex devicelist">-->
					<!--<div class="flex-1">-->
						<!--1111111-->
					<!--</div>-->
					<!--<div class="flex-1">-->
						<!--三个月包月套餐-->
					<!--</div>-->
					<!--<div class="flex-1">-->
						<!--2018-1-1-->
					<!--</div>-->
				<!--</div>-->


			</div>

			<div class="businessmore hide" onclick="ajax_devicejihuo_submit()">
				<p>查看等多</p>
				<p class="companyicon businessmoreicon">
					<i class="iconfont comicon">&#xe624;</i>
				</p>
			</div>

		</div>
		<!--已激活设备设备end-->

		<!--未激活设备设备-->
		<div class="devicelistbox" id="notactive">
			<div class="flex devicehead">
				<div class="flex-1">设备号</div>
				<div class="flex-1">状态</div>
			</div>

			<div class="nulldecice">
				<p class="iconfont ">&#xe6ed;</p>
				<p class="nulldevicetitle">您还没有wifi设备</p>
			</div>

			<div class="deviceinfo" id="notactivelist">
				<!--<div class="flex devicelist">-->
					<!--<div class="flex-1">-->
						<!--1111111-->
					<!--</div>-->
					<!--<div class="flex-1">-->
						<!--未激活-->
					<!--</div>-->

				<!--</div>-->


			</div>

			<div class="businessmore hide" onclick="ajax_deviceactivelist_submit()">
				<p>查看等多</p>
				<p class="companyicon businessmoreicon">
					<i class="iconfont comicon">&#xe624;</i>
				</p>
			</div>


		</div>
		<!--未激活设备设备end-->



	</div>



</main>


<script>

	var tooken=$.cookie("tooken");


	if(tooken==null||tooken==undefined||tooken==""){

		window.location.href="../agent/login.html";

	}else {
		var agentid=getUrlParam("agentid");
		var page=1;

		// var url="http://qt.hiberbest.com";
		//var url="http://192.168.0.132:69";

		getAjaxDevice(0);


		function getAjaxDevice(type){

			if(type == 0 ){
				var geturl=url+ "/admin/deviceapi/getDeviceByAgentid?agentid="+agentid+"&page=1&limit=10";

				$.ajax({
					type: 'get',
					dataType: "json",
					url: geturl,
					success: function (data) {
						console.log(data);

						var count=data.count;
						var jihuo=count.jihuo;
						var all=count.count;
						var nulldevice=all-jihuo;
						$('#alldevice').html(all);
						$('#devicejihuo').html(jihuo);
						$('#divecenull').html(nulldevice);

						var suc = data.success;
						if (suc.code == 4007) {
							alert(suc.message);
							//window.location.href="login.html";
						} else if (suc.code == 4011) {
							alert(suc.message);
							//window.location.href = "login.html";
						} else if (suc.code == 4000) {
							var deviceList=data.deviceList;
							var str="";

							if(deviceList.length == 0){
								$('#totallist').siblings(".nulldecice").show();
								return false;
							}

							if(deviceList.length >= 5){
								$('#totallist').siblings(".businessmore").removeClass("hide");
							}

							for(var i=0;i<deviceList.length;i++){
								str+='<div class="flex devicelist">' +
										'<div class="flex-1">' +
										''+deviceList[i].device_sn+'' +
										'</div>' +
										'<div class="flex-1">' +
										''+deviceList[i].taocan['flow']+'' +
										'</div>' +
										'<div class="flex-1">' +
										''+deviceList[i].taocan['addtime']+'' +
										'</div>' +
										'</div>'
							}



							$('#totallist').html(str);
							$('#totallist').siblings(".nulldecice").hide();
						}
					}

				});
			}else if(type == 1){
				var jihuo=1;
				var geturl=url+ "/admin/deviceapi/getDeviceByAgentid?agentid="+agentid+"&page=1&limit=10"+"&jihuo="+jihuo;

				$.ajax({
					type: 'get',
					dataType: "json",
					url: geturl,
					success: function (data) {
						console.log(data);
						var suc = data.success;
						if (suc.code == 4007) {
							alert(suc.message);
							//window.location.href="login.html";
						} else if (suc.code == 4011) {
							alert(suc.message);
							//window.location.href = "login.html";
						} else if (suc.code == 4000) {
							var deviceList=data.deviceList;
							var str="";

							if(deviceList.length == 0){
								$('#activationlist').siblings(".nulldecice").show();
								return false;
							}

							if(deviceList.length >= 5){
								$('#activationlist').siblings(".businessmore").removeClass("hide");
							}

							for(var i=0;i<deviceList.length;i++){
								str+='<div class="flex devicelist">' +
										'<div class="flex-1">' +
										''+deviceList[i].device_sn+'' +
										'</div>' +
										'<div class="flex-1">' +
										''+deviceList[i].taocan['flow']+'' +
										'</div>' +
										'<div class="flex-1">' +
										''+deviceList[i].taocan['addtime']+'' +
										'</div>' +
										'</div>'
							}

							$('#activationlist').html(str);
							$('#activationlist').siblings(".nulldecice").hide();
						}
					}

				});
			}else if(type == 2){
				var jihuo=0;
				var geturl=url+ "/admin/deviceapi/getDeviceByAgentid?agentid="+agentid+"&page=1&limit=10"+"&jihuo="+jihuo;

				$.ajax({
					type: 'get',
					dataType: "json",
					url: geturl,
					success: function (data) {
						console.log(data);
						var suc = data.success;
						if (suc.code == 4007) {
							alert(suc.message);
							//window.location.href="login.html";
						} else if (suc.code == 4011) {
							alert(suc.message);
							//window.location.href = "login.html";
						} else if (suc.code == 4000) {
							var deviceList=data.deviceList;
							var str="";

							if(deviceList.length == 0){
								$('#notactivelist').siblings(".nulldecice").show();
								return false;
							}
							if(deviceList.length >= 5){
								$('#notactivelist').siblings(".businessmore").removeClass("hide");
							}

							for(var i=0;i<deviceList.length;i++){
								str+='<div class="flex devicelist">' +
										'<div class="flex-1">' +
										''+deviceList[i].device_sn+'' +
										'</div>' +
										'<div class="flex-1">' +
										''+deviceList[i].taocan['addtime']+'' +
										'</div>' +
										'</div>'
							}


							$('#notactivelist').html(str);
							$('#notactivelist').siblings(".nulldecice").hide();
						}
					}

				});
			}



		}




		/*加载更多*/

		/*全部设备*/
		function ajax_device_submit() {

			page += 1;

			//console.log(page);
			$.ajax({
				type : "GET",
				dataType: "json",
				url:url + "/admin/deviceapi/getDeviceByAgentid?agentid="+agentid+"&limit=10&page="+page,
				success: function(data) {

					var deviceList=data.deviceList;


					if(deviceList.length == 0){
						layui.use('layer', function(){
							var layer = layui.layer;

							layer.msg('没有更多数据了');
						});

					}else{

						var str="";
						for(var i=0;i<deviceList.length;i++){

							str+='<div class="flex devicelist">' +
									'<div class="flex-1">' +
									''+deviceList[i].device_sn+'' +
									'</div>' +
									'<div class="flex-1">' +
									''+deviceList[i].taocan['flow']+'' +
									'</div>' +
									'<div class="flex-1">' +
									''+deviceList[i].taocan['addtime']+'' +
									'</div>' +
									'</div>'

						}


						$("#totallist").append(str);

					}
				}
			});
		}


		/*已激活设备*/

		function ajax_devicejihuo_submit() {

			page += 1;
			var jihuo=1;

			$.ajax({
				type : "GET",
				dataType: "json",
				url:url + "/admin/deviceapi/getDeviceByAgentid?agentid="+agentid+"&limit=10&page="+page+"&jihuo="+jihuo,
				success: function(data) {

					var deviceList=data.deviceList;


					if(deviceList.length == 0){
						layui.use('layer', function(){
							var layer = layui.layer;

							layer.msg('没有更多数据了');
						});

					}else{

						var str="";
						for(var i=0;i<deviceList.length;i++){

							str+='<div class="flex devicelist">' +
									'<div class="flex-1">' +
									''+deviceList[i].device_sn+'' +
									'</div>' +
									'<div class="flex-1">' +
									''+deviceList[i].taocan['flow']+'' +
									'</div>' +
									'<div class="flex-1">' +
									''+deviceList[i].taocan['addtime']+'' +
									'</div>' +
									'</div>'

						}


						$("#totallist").append(str);

					}
				}
			});
		}


		/*未激活设备*/

		function ajax_deviceactivelist_submit() {

			page += 1;
			var jihuo=0;

			$.ajax({
				type : "GET",
				dataType: "json",
				url:url + "/admin/deviceapi/getDeviceByAgentid?agentid="+agentid+"&limit=10&page="+page+"&jihuo="+jihuo,
				success: function(data) {

					var deviceList=data.deviceList;


					if(deviceList.length == 0){
						layui.use('layer', function(){
							var layer = layui.layer;

							layer.msg('没有更多数据了');
						});

					}else{

						var str="";
						for(var i=0;i<deviceList.length;i++){

							str+='<div class="flex devicelist">' +
									'<div class="flex-1">' +
									''+deviceList[i].device_sn+'' +
									'</div>' +

									'<div class="flex-1">' +
									''+deviceList[i].taocan['flow']+'' +
									'</div>' +
									'</div>'

						}


						$("#notactivelist").append(str);

					}
				}
			});
		}






		function device(e,type){
			if(type == 0){
				$(e).addClass("co-deepblue").siblings().removeClass("co-deepblue");
				getAjaxDevice(0);
				$('#total').show();
				page=1;
				$('#activation,#notactive').hide();
			}else if(type==1){
				$(e).addClass("co-deepblue").siblings().removeClass("co-deepblue");
				getAjaxDevice(1);
				$('#activation').show();
				page=1;
				$('#total,#notactive').hide();
			}else if(type==2){
				$(e).addClass("co-deepblue").siblings().removeClass("co-deepblue");
				getAjaxDevice(2);
				$('#notactive').show();
				page=1;
				$('#total,#activation').hide();
			}
		}


	}






</script>


</body>
</html>
